home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS08.ADF / Text / FixLatticeMain < prev    next >
Text File  |  1986-04-02  |  3KB  |  69 lines

  1. Lattice C V3.02 does not provide full Unix compatability on its command
  2. line parser.  Most of the time that's OK, but there are two situations
  3. where that's not good enough. first, any program that wants to be able to
  4. handle as an argument any valid Amiga filename will not work
  5. (i.e. "TEST FILE"), because blanks are seen as delimiters, the file name
  6. will be broken into two arguments: '"TEST', and 'PARM"'.  Secondly, certain
  7. arguments to GREP which would require the pattern string to be in quotes
  8. will not work for the same reason.  I mentioned this to Lattice, but they
  9. didn't see fit to comment on it, so I don't know if V3.03 or later fixes the
  10. problem.  Fortunately, you can do this yourself.  Included in the 'examples'
  11. directory on the distribution disk is the module "_main".  The first thing
  12. you need to do is remove the binary trash that's in the file so that ED
  13. can edit it.
  14.  
  15. The Lattice version has a simple solution to parsing the
  16. command line: it skips over spaces, fills the argument array with pointers
  17. to the first non-space character of each argument, and then jams a NULL
  18. where the trailing space or null is.  The way that they did it is tacky and
  19. in my mind dangerous - they modify the parm string owned by the
  20. AmigaDos CLI.  I recommend that you 'strcpy' the parm into a local string
  21. (128 bytes should be adequate) and mutilate IT, instead.  That way, should
  22. Commodore-Amiga decide to look at its parm string after the program has
  23. been called in some future release (don't ask me why) or store it in
  24. protected memory, etc., you won't experience mysterious program and/or system
  25. failures.
  26.  
  27. Anyway, to handle the quoted parameter problem - I'm not sure about Unix,
  28. but my CP/M system accepted both single and double quotes as delimiters, so
  29. that's the way I set it up here:
  30.  
  31. #define NULL '\0'
  32. #define SINGLE_QUOTE '\''
  33. #define DOUBLE_QUOTE '\"'
  34.  
  35. /*---- replace main program's for loop innards with the following... */
  36.  
  37.  {
  38.    while (isspace(*line)) line++;   /* skip leading spaces */
  39.    if (*line == NULL) break;
  40.    if ((*line == SINGLE_QUOTE) || (*line == DOUBLE_QUOTE))
  41.       quote_it (*line);
  42.    else
  43.    {
  44.       argv[argc++] = line;          /* pointer to parm */
  45.       while (!isspace(*line) && (*line != NULL)) line++; /* scan characters */
  46.    }
  47.       ... leave rest of Lattice stuff as is ....
  48.  }
  49.  
  50. void
  51. quote_it (delimiter)       /* handle quotes - define as void prior to above */
  52. char * delimiter;
  53. {
  54.    argv[argc++] = ++line;  /* point to text of string */
  55.    while ((*line != delimiter) && (*line != NULL)) line++;
  56.    /* now let main program jam null over closing delimiter */
  57. }
  58.  
  59. You may notice that this code doesn't give a hang about screwed up or
  60. missing final quotes.  You can insert error messages if you like, just
  61. remember that the TINY option if selected will remove access to stdout and
  62. stderr - by definition.
  63.  
  64. I haven't tried this out myself yet, but it should be substantially correct.
  65. If it isn't let me (and the rest of us!) know.  Your updated _main goes (I
  66. think!) into the C 'lib' directory as 'Lstartup.obj'.  Good Luck!
  67.  
  68.          Tim Holloway [73026,2026]
  69.